 #define _CRT_SECURE_NO_WARNINGS 1

//#include <iostream>
//#include <string>
//#include <vector>
//#include <cmath>
//using namespace std;
//
//int main() {
//
//    string s1, s2;
//    int len1, len2;
//    while (cin >> s1 >> s2 >> len1 >> len2)
//    {
//        s1.append(len2 - s1.size(), 'a');
//        s2.append(len2 - s2.size(), (char)('z' + 1));
//
//        vector<int> v;
//        for (int i = 0; i < len2; i++)
//            v.push_back(s2[i] - s1[i]);
//
//        int ret = 0;
//        for (int i = len1; i <= len2; i++)
//            for (int j = 0; j < i; j++)
//                ret += v[j] * pow(26, i - 1 - j);
//
//        cout << ret - 1 << endl;
//    }
//    return 0;
//}

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int main() {

    string s1, s2;
    while (cin >> s1 >> s2)
    {
        int m = s1.size(), n = s2.size();

        vector<vector<int>> dp(m + 1, vector<int>(n + 1));

        s1 = " " + s1;
        s2 = " " + s2;

        for (int i = 1; i <= m; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                if (s1[i] == s2[j]) dp[i][j] = dp[i - 1][j - 1] + 1;
                else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
        cout << dp[m][n] << endl;
    }
    return 0;
}
